package com.bdqn.base.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 *
 * @author lilibo
 * @since 2019-09-20
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 测试环境开启
     */
    @Value("${system.swagger.enable}")
    private boolean enable;

    @Bean("cloudApi")
    public Docket cloudApi() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("CloudApi").select().apis(RequestHandlerSelectors.basePackage("com.bdqn")).paths(PathSelectors.any()).build().apiInfo(apiInfo()).enable(enable);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("接口文档").description("接口文档").version("1.0").build();
    }

}